<?php

$end = microtime(true);
if ( ! defined("QI_AUTO_APPEND_FILE_TIME") ) return;
$t = QI_AUTO_APPEND_FILE_TIME;
$elapse = $end - $t;

$dados = array();

$dados["time"] = array(
	"start" => $t,
	"end" => $end,
	"elapse" => $elapse
);

$dados["memory"] = array(
	"peak_system" => memory_get_peak_usage(),
	"peak_emalloc" => memory_get_peak_usage(true),
	"atual_system" => memory_get_usage(),
	"atual_emalloc" => memory_get_usage(true)
);

$dados["included_files"] = get_included_files();

$server_keys = "HTTP_HOST HTTP_USER_AGENT REMOTE_ADDR REMOTE_PORT REQUEST_METHOD QUERY_STRING PHP_SELF SCRIPT_NAME REQUEST_URI PATH_INFO";
$server_keys = explode(" ", $server_keys);
$server = array();
foreach($server_keys as $k):
	$server[$k] = isset($_SERVER[$k]) ? $_SERVER[$k] : null;
endforeach;
$dados["server"] = $server;

$dados["headers_list"] = headers_list();

$var = var_export($dados, true);

$tpl = "\$dados[$t] = $var;\n";

$logdir = "D:/wampBR/tmp/php/timelog";
$dir = strftime("$logdir/%Y.%m/d%d/h%H");
if (!is_dir($dir)) mkdir($dir, 0777, true);
$file = strftime("$dir/m%M.php");

if (!file_exists($file)):
	$fp = fopen($file, "w");
	fwrite($fp, "<? \$dados = array();\n\n");
else:
	$fp = fopen($file, "a");
endif;

fwrite($fp, $tpl);
fclose($fp);

?>